Completed
Push — master ( dc838b...dfb2bc )
by Askupa
01:34
created

Amarkal.settings.fields.search   A

Complexity

Conditions 1
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 18
rs 9.4285

2 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 11 4
A 0 1 1
1
Amarkal.settings.fields = {
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
    $fields: null,
3
    init: function () {
4
        this.$fields = $('.amarkal-settings-field');
5
    },
6
    hideAll: function () {
7
        this.hide(this.$fields);
8
    },
9
    showAll: function () {
10
        this.show(this.$fields);
11
    },
12
    showBySection: function (slug) {
13
        this.hideAll();
14
        this.show(this.$fields.filter('[data-section="'+slug+'"]'));
15
    },
16
    search: function(query) {
17
        var matches  = [];
18
        
19
        this.$fields.each(function(){
20
            var $field = $(this),
21
                title  = $field.find('h3').text().toLowerCase(),
22
                help = $field.find('.help-content').text();
23
                description = $field.find('.description').text();
0 ignored issues
show
Bug introduced by
The variable description seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.description.
Loading history...
24
25
            // Check query against the field's title
26
            if(title.match(query) || description.match(query) || help.match(query)) {
27
                matches.push($field);
28
            }
29
        });
30
31
        // Convert the matches array to a jQuery object
32
        return $(matches).map(function(){return this.toArray();});
33
    },
34
    show: function($fields) {
35
        $fields
36
            .addClass('visible')
37
            .find('.amarkal-ui-component')
38
            .amarkalUIComponent('refresh');
39
    },
40
    hide: function($fields) {
41
        $fields.removeClass('visible');
42
    },
43
    flag: function(type, fieldName) {
44
        this.$fields.filter('[data-name="'+fieldName+'"]').addClass('flag-'+type);
45
    }
46
};